/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package function;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.InputInterFace;
import mainpackage.MainCanvas;
import mainpackage.MainGame;
import mainpackage.MainLogic;
import mainpackage.ResManager;
import mainpackage.Tools;
import ui.UiEquipment;

/**
 *
 * @author Administrator
 */
public class Tong {

    private Image[] imgArray = null;
    private String[] sArray = null;
    private int[] iArray = null;
    private int iUiX = 0;
    private int iUiY = 0;
    private int startX = 0;
    private int startY = 0;
    private int w = 0;
    private int h = 0;
    private int selectColor = 0x00CCFF;
    private int blackColor = 0x000000;
    private int whiteColor = 0xFFFFFF;
    public int iPositionY = 0;
    private boolean bUiKeyPressLock = false;
    private int iWidth = 0;
    private int iHeight = 0;
    private int iStartX = 0;
    private int iStartY = 0;
    private byte byPopUpState = -1; //记录界面弹出层的UI状态变化
    private byte byState = 0; //记录在跟新页面状态的时候的小状态
    private byte bySelectIndex;
    public byte byTongUiState = 0;
    private byte selectNum;
    private byte num;//每页最多显示的帮派或帮派成员数量
    private short sCurrentPage, sTotalPage;
    private int tongNum;//帮派数量
    public int index;//索引
    private int tempIndex;//临时索引
    public long[] tongId;//帮派ID
    private String[] tongName;//帮派名字
    public byte[] duty;//职位
    private int[] level;//级别
    private byte[] onLine;//是否在线
    private byte[] tongLv;//帮派等级
    private byte[] tongMerNum;//帮派人数
    private long[] tongDate;//建帮时间
    public String[] sData;
    private String[] menu;//弹出菜单项
    private byte menuSelectIndex;
    private int menuWidth;//弹出menu菜单的总宽度
    private int menuHeight;//弹出menu菜单的总高度
    private int menuPositionY;
    private int menuH;//每条menu菜单的高度
    private int menuSpaceH;//每2个menu间的间隔高度
    private String[] tongNameVs;
    private int[] levelVs;
    private int tempVsIndex;

    /*****************创建帮派***************************************/
    public Tong() {
//        this.init();
    }

    public void init() {
//        switch (MainLogic.getInstance().byGameState) {
//            case Constant.GAME_UI_TONG_SKILL:
//                initTongSkill();
//                break;
//        }
    }

    public void initCreateTong() {
        GameBean.b_WAIT_NET_MSG_BACK = false;
        this.bUiKeyPressLock = false;
        this.byState = 0;
        //界面中的位置的统一配置
        this.bySelectIndex = 1;
        this.byTongUiState = 0;
        this.sArray = new String[]{"创建帮派", "帮派名称：", "帮派代号：",//0 - 2
            "帮派宣言：", "<a帮派宣言>：", "创建帮派需要花费1金币，需要建帮令牌，需要等级20",//3 - 5
            "帮派名字长度", "返回"//6 - 7
        };
        //#if NOKIA_S60V5
         imgArray = new Image[8];
         imgArray[0] = ResManager.createImage(90000041);//箭头图片
         imgArray[1] = Tools.makeBlueMask();//蓝光图片
         imgArray[2] = ResManager.createImage(90000017);//背景图片
         imgArray[3] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x252525);//半透明背景
         imgArray[4] = ResManager.createImage(90000043);//文字图片
         imgArray[5] = ResManager.createImage(90000084);//方向键
         imgArray[6] = ResManager.createImage(90000085);//确定键
         imgArray[7] = ResManager.createImage(90000086);//底部蓝条
         iPositionY = Constant.UI_START_Y + 41 + Constant.FONT_SMALL_HEIGHT + 20;
        //#else
//#        imgArray = new Image[5];
//#        this.iPositionY = Constant.UI_START_Y + 30 + Constant.FONT_SMALL_HEIGHT + 3;
//#        try {
//#            //箭头图片
//#            this.imgArray[0] = ResManager.createImage(90000041);//箭头图片
//#            //蓝色光片
//#            this.imgArray[1] = Tools.makeBlueMask();
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[2] = ResManager.createImage(90000017);
//# //            imgArray[2] = Tools.ZoomImage(imgArray[2], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            this.imgArray[2] = ResManager.createImage(90000017);
            //#endif
//#
//#            //半透背景图片
//#            this.imgArray[3] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x252525);
//#            //文字图片
//#            this.imgArray[4] = ResManager.createImage(90000043);
//#        } catch (Exception e) {
//#            if (Constant.DEBUG) {
//#                e.printStackTrace();
//#            }
//#        }
        //#endif
    }

    public void updateCreateTong() {
        if (byTongUiState == 0) {
            if (!bUiKeyPressLock) {
                if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                    bUiKeyPressLock = true;
                    bySelectIndex = (byte) (bySelectIndex == 1 ? 3 : (bySelectIndex - 1));
                    //#if NOKIA_S60V5
                     h = Constant.FONT_SMALL_HEIGHT + 20;
                     startY = Constant.UI_START_Y + 41 + h * bySelectIndex;
                    //#else
//#                    h = Constant.FONT_SMALL_HEIGHT + 3;
//#                    startY = Constant.UI_START_Y + 30 + h * bySelectIndex;
                    //#endif
                    iArray = new int[]{2, 1, startY, 2, 50, 5};
                } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                    bUiKeyPressLock = true;
                    bySelectIndex = (byte) (bySelectIndex == 3 ? 1 : (bySelectIndex + 1));
                    //#if NOKIA_S60V5
                     h = Constant.FONT_SMALL_HEIGHT + 20;
                     startY = Constant.UI_START_Y + 41 + h * bySelectIndex;
                    //#else
//#                    h = Constant.FONT_SMALL_HEIGHT + 3;
//#                    startY = Constant.UI_START_Y + 30 + h * bySelectIndex;
                    //#endif
                    iArray = new int[]{1, 1, startY, 2, 50, 5};
                } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false)
                        || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                    if (this.bySelectIndex == 1) {
                        //输入帮派名称
                        MainLogic.inputInterFace.setInputInterFace(this.byTongUiState, "请输入帮派名称：");
                        MainGame.changeCanvas(MainLogic.inputInterFace);
                    } else if (this.bySelectIndex == 2) {
                        //输入帮派代号
                        MainLogic.inputInterFace.setInputInterFace(this.byTongUiState, "请输入帮派口号：");
                        MainGame.changeCanvas(MainLogic.inputInterFace);
                    } else if (this.bySelectIndex == 3) {
                        //输入帮忙宣言
                        MainLogic.inputInterFace.setInputInterFace(this.byTongUiState, "请输入帮派宣言：");
                        MainGame.changeCanvas(MainLogic.inputInterFace);
                    }
                } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                    //帮派建立确认键
                    if (GameBean.STR_CMD_TONG_NAME == null) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请输入帮派名称！");
                    } else if (GameBean.STR_CMD_TONG_NO == null) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请输入帮派代号！");
                    } else if (GameBean.STR_CMD_TONG_ADS == null) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请输入帮派宣言！");
                    } else if (GameBean.STR_CMD_TONG_NAME.length() < 3 || GameBean.STR_CMD_TONG_NAME.length() > 6) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "帮派名称的长度(3到6个字符)不正确！");
                    } else if (GameBean.STR_CMD_TONG_NO.length() != 1) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "帮派代号的长度(1个字符)不正确！");
                    } else if (GameBean.STR_CMD_TONG_NAME.indexOf(GameBean.STR_CMD_TONG_NO) == -1) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "帮派代号必须是帮派名称中的一个字符！");
                    } else if (GameBean.STR_CMD_TONG_ADS.length() < 3 || GameBean.STR_CMD_TONG_ADS.length() > 50) {
                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "帮派宣言的长度(3到30个字符)不正确！");
                    } else {
                        //发送创建帮派的指令
                        MainLogic.getInstance().send(Constant.MSG_NET_CREATE_TONG, Constant.SOCKET_MSG_TYPE_LOGIC);
                        this.bUiKeyPressLock = true;
                        MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                    }
                } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一界面
                    MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                }
            } else {
                this.iPositionY = Tools.updateLinePos(iArray, this.iPositionY);
                if (this.iArray == null || this.iArray[1] == 0) {
                    this.bUiKeyPressLock = false;
                }
            }
            MainCanvas.clearInput();
        }
    }

    public void drawCreateTong(Graphics g) {
        if (this.byTongUiState > 0) {
            return;
        }
        //绘制背景
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, imgArray[2], imgArray[5], imgArray[6], imgArray[7], imgArray[4], 52, 2, 43, 22, imgArray[4], 197, 0, 95, 25, sArray[0]);
        //#else
//#        h = imgArray[4].getHeight();
//#        Tools.drawFrame(g, imgArray[2], imgArray[1], sArray[0], sArray[7], sArray[0]);
        //#endif
        //绘制输入帮派名称
        //#if NOKIA_S60V5
         h = Constant.FONT_SMALL_HEIGHT + 20;
         startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
         w = Constant.DRAW_WIDTH - 50;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 3;
//#        startY = Constant.UI_START_Y + 30;
//#        w = Constant.FONT_SMALL.stringWidth(sArray[1] + sArray[6]);
        //#endif
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        Tools.drawShadowString(g, (byte) 1, sArray[1], startX, startY, selectColor, blackColor);
        if (GameBean.STR_CMD_TONG_NAME != null) {
            Tools.drawShadowString(g, (byte) 1, GameBean.STR_CMD_TONG_NAME, startX + Constant.FONT_SMALL.stringWidth(sArray[1]),
                    startY, whiteColor, blackColor);
        }
        //绘制输入帮派代号
        startY = startY + h;
        Tools.drawShadowString(g, (byte) 1, sArray[2], startX, startY, selectColor, blackColor);
        if (GameBean.STR_CMD_TONG_NO != null) {
            Tools.drawShadowString(g, (byte) 1, GameBean.STR_CMD_TONG_NO, startX + Constant.FONT_SMALL.stringWidth(sArray[2]),
                    startY, whiteColor, blackColor);
        }
        //绘制帮派宣言
        startY = startY + h;
        if (GameBean.STR_CMD_TONG_ADS == null) {
            Tools.drawShadowString(g, (byte) 1, sArray[3], startX, startY, selectColor, blackColor);
        } else {
            Tools.drawParagraph(g, startX, startY, w, sArray[4] + GameBean.STR_CMD_TONG_ADS, whiteColor, h, blackColor);
        }
        //绘制建帮条件
        startX = Constant.UI_START_X + 0;
        //#if NOKIA_S60V5
         startY = Constant.END_LINE - Tools.getParagraphHeight(sArray[5], w, h);
        //#else
//#        h = Tools.getParagraphHeight(sArray[5], w, h) + 10;
//#        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25 - h;
        //#endif
        w = Constant.DRAW_WIDTH;
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[3], 0, 0, w, 10, Constant.TRANS_NONE);
        //#if NOKIA_S60V5
         w = Constant.DRAW_WIDTH - 50;
         h = Constant.FONT_SMALL_HEIGHT + 20;
         startY += (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#else
//#        w = Constant.FONT_SMALL.stringWidth(sArray[1] + sArray[6]);
//#        h = Constant.FONT_SMALL_HEIGHT + 3;
//#        startY += 10;
        //#endif
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        Tools.drawParagraph(g, startX, startY, w, sArray[5], whiteColor, h, blackColor);
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, iPositionY, w);
    }

    public void clearCreateTong() {
        imgArray = null;
        sArray = null;
    }

    /********************帮派列表*******************************************/
    public void initTongList() {
        bUiKeyPressLock = false;
        startX = 0;
        startY = 0;
        byState = 0;
        //#if NOKIA_S60V5
         imgArray = new Image[10];
         imgArray[0] = ResManager.createImage(90000041);//箭头图片
         imgArray[1] = Tools.makeBlueMask();//蓝色光片
         imgArray[2] = ResManager.createImage(90000017);//背景图片
         imgArray[3] = Tools.makeTransparent(Constant.DRAW_WIDTH, 10, 220, 0x232323);//半透背景图片
         imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
         imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
         imgArray[6] = ResManager.createImage(90000047);//数字图片
         imgArray[7] = ResManager.createImage(90000084);//方向键
         imgArray[8] = ResManager.createImage(90000085);//确定键
         imgArray[9] = ResManager.createImage(90000086);//底部蓝条
        //#else
//#        imgArray = new Image[7];
//#        try {
//#            imgArray[0] = ResManager.createImage(90000041);//箭头图片
//#            imgArray[1] = Tools.makeBlueMask();//蓝色光片
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[2] = ResManager.createImage(90000017);
//# //            imgArray[2] = Tools.ZoomImage(imgArray[2], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            this.imgArray[2] = ResManager.createImage(90000017);
            //#endif
//#            imgArray[3] = Tools.makeTransparent(Constant.DRAW_WIDTH, 10, 220, 0x232323);//半透背景图片
//#            imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
//#            imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
//#            imgArray[6] = ResManager.createImage(90000047);//数字图片
//#        } catch (Exception e) {
//#            if (Constant.DEBUG) {
//#                e.printStackTrace();
//#            }
//#        }
        //#endif

        //测试
//        initTongNum(24);
//        for (int i = 0; i < 24; i++) {
//            getTongListInformation(i, i, "测试测试才" + i, (byte) i, (byte) i, i);
//        }
    }

    public void initTongNum(int tongNum) {
        this.tongNum = tongNum;
        tongId = new long[tongNum];
        tongName = new String[tongNum];
        tongLv = new byte[tongNum];
        tongMerNum = new byte[tongNum];
        tongDate = new long[tongNum];

        sArray = new String[]{"帮派列表", "Lv", " - ", "Lv30 - 测试帮派长度",//0 - 3
            "确定", "返回" //4 - 5
        };
        //#if NOKIA_E72
//#         num = 5;
        //#else
        num = 10;
        //#endif

        sCurrentPage = 1;
        sTotalPage = (short) ((tongNum % num > 0 || tongNum == 0) ? (tongNum / num + 1) : (tongNum / num));
//        selectNum = (sCurrentPage * num < tongNum) ? (byte) (num + 2) : (byte) (tongNum - (sCurrentPage - 1) * num + 2);
        selectNum = (sCurrentPage * num < tongNum) ? (byte) (num + 1) : (byte) (tongNum - (sCurrentPage - 1) * num + 1);
        bySelectIndex = 1;
        //#if NOKIA_S60V5
         iPositionY = Constant.UI_START_Y + 41;
        //#else
//#        iPositionY = Constant.UI_START_Y + 21;
        //#endif
    }

    public void getTongListInformation(int index, long tongId, String tongName, byte lv, byte merNum, long date) {
        this.tongId[index] = tongId;
        this.tongName[index] = tongName;
        tongLv[index] = lv;
        tongMerNum[index] = merNum;
        tongDate[index] = date;

        //排序  等级、人数、建帮时间
        setTongListOrder();
    }

    public void setTongListOrder() {//排序  等级、人数、建帮时间
        long tempId = -1;
        String tempName = null;
        byte tempLv = -1;
        byte tempMerNum = -1;
        long tempDate = -1;
        for (int i = 0; i < this.tongId.length; i++) {
            for (int j = i; j < this.tongId.length; j++) {

                if (tongDate[i] > tongDate[j]) {//建帮时间早的靠前
                    tempId = tongId[i];
                    tempName = this.tongName[i];
                    tempLv = tongLv[i];
                    tempMerNum = tongMerNum[i];
                    tempDate = tongDate[i];

                    tongId[i] = tongId[j];
                    this.tongName[i] = this.tongName[j];
                    tongLv[i] = tongLv[j];
                    tongMerNum[i] = tongMerNum[j];
                    tongDate[i] = tongDate[j];

                    tongId[j] = tempId;
                    this.tongName[j] = tempName;
                    tongLv[j] = tempLv;
                    tongMerNum[j] = tempMerNum;
                    tongDate[j] = tempDate;
                }

                if (tongMerNum[i] < tongMerNum[j]) {//人数由多到少
                    tempId = tongId[i];
                    tempName = this.tongName[i];
                    tempLv = tongLv[i];
                    tempMerNum = tongMerNum[i];
                    tempDate = tongDate[i];

                    tongId[i] = tongId[j];
                    this.tongName[i] = this.tongName[j];
                    tongLv[i] = tongLv[j];
                    tongMerNum[i] = tongMerNum[j];
                    tongDate[i] = tongDate[j];

                    tongId[j] = tempId;
                    this.tongName[j] = tempName;
                    tongLv[j] = tempLv;
                    tongMerNum[j] = tempMerNum;
                    tongDate[j] = tempDate;
                }

                if (tongLv[i] < tongLv[j]) {//级别由高到低
                    tempId = tongId[i];
                    tempName = this.tongName[i];
                    tempLv = tongLv[i];
                    tempMerNum = tongMerNum[i];
                    tempDate = tongDate[i];

                    tongId[i] = tongId[j];
                    this.tongName[i] = this.tongName[j];
                    tongLv[i] = tongLv[j];
                    tongMerNum[i] = tongMerNum[j];
                    tongDate[i] = tongDate[j];

                    tongId[j] = tempId;
                    this.tongName[j] = tempName;
                    tongLv[j] = tempLv;
                    tongMerNum[j] = tempMerNum;
                    tongDate[j] = tempDate;
                }
            }
        }
    }

    public void updateTongList() {
        if (GameBean.b_WAIT_NET_MSG_BACK) {
            return;
        }
        if (!bUiKeyPressLock) {
            switch (byState) {
                case 0:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            if (selectNum > 1) {
                                //#if NOKIA_S60V5
                                 h = (Constant.END_LINE - (41 << 1)) / num;
                                 startY = Constant.UI_START_Y + (41 << 1) + h * (selectNum - 2);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                startY = Constant.UI_START_Y + 65 + h * (selectNum - 2);
                                //#endif
                                bySelectIndex = selectNum;
                            } else {
                                return;
                            }
                        } else if (bySelectIndex == 2) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / num;
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 3);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 3);
                            //#endif
                            bySelectIndex--;
                        }
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == selectNum) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / num;
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 1);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 1);
                            //#endif
                            bySelectIndex++;
                        }
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)) {
                        if (sCurrentPage > 1) {//向左翻页
                            bUiKeyPressLock = true;
                            sCurrentPage--;
                            selectNum = (byte) ((sCurrentPage * num < tongNum) ? num + 1 : tongNum - (sCurrentPage - 1) * num + 1);
                            //#if NOKIA_S60V5
                             iPositionY = Constant.UI_START_Y + 41;
                            //#else
//#                            iPositionY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
                        if (sCurrentPage < sTotalPage) {//向右翻页
                            bUiKeyPressLock = true;
                            sCurrentPage++;
                            selectNum = (byte) ((sCurrentPage * num < tongNum) ? num + 1 : tongNum - (sCurrentPage - 1) * num + 1);
                            //#if NOKIA_S60V5
                             iPositionY = Constant.UI_START_Y + 41;
                            //#else
//#                            iPositionY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                        if (bySelectIndex > 1) {
                            bUiKeyPressLock = true;
                            if (MainLogic.getInstance().gamePlayer.sTongName == null) {
                                menu = new String[]{"查看详情", "传送家园", "申请加入"};
                            } else {
                                menu = new String[]{"查看详情", "传送家园"};
                            }
                            //#if NOKIA_S60V5
                             menuH = (Constant.END_LINE - (41 << 1)) / num;
                             menuSpaceH = 20;
                            //#else
//#                            menuH = Constant.FONT_SMALL_HEIGHT + 2;
//#                            menuSpaceH = 10;
                            //#endif
                            menuWidth = Constant.DRAW_WIDTH >> 1;
                            menuHeight = menu.length * (menuH + menuSpaceH) - menuSpaceH;
                            menuSelectIndex = (byte) (menu.length % 2 == 0 ? (menu.length >> 1) : (menu.length >> 1) + 1);
                            //#if NOKIA_S60V5
                             menuPositionY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                     + menuSelectIndex * (menuH + menuSpaceH);
                            //#else
//#                            menuPositionY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                    + menuSelectIndex * (menuH + menuSpaceH);
                            //#endif
                            byState = 1;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级页面
                        bUiKeyPressLock = true;
                        MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                    }
                    break;
                case 1:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        bUiKeyPressLock = true;
                        tempIndex = (sCurrentPage - 1) * num + bySelectIndex - 2;
                        GameBean.L_CMD_TONG_ID = tongId[tempIndex];
                        switch (menuSelectIndex) {
                            case 1://查看详情
                                GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_TONG_LIST;
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DESCRIPT, Constant.SOCKET_MSG_TYPE_LOGIC);
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                break;
                            case 2://传送家园
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_FUNC_TONG_TRANS, Constant.SOCKET_MSG_TYPE_LOGIC);
                                break;
                            case 3://申请加入
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_APPLICATION_TONG, Constant.SOCKET_MSG_TYPE_LOGIC);
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "申请已发出!", (byte) 1, (byte) -1);
                                break;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级页面
                        bUiKeyPressLock = true;
                        byState = 0;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == 1 ? menu.length : (menuSelectIndex - 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == menu.length ? 1 : (menuSelectIndex + 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    }
                    break;
            }
        } else {
            switch (byState) {
                case 0:
                    iPositionY = Tools.updateLinePos(iArray, iPositionY);
                    break;
                case 1:
                    menuPositionY = Tools.updateLinePos(iArray, menuPositionY);
                    break;
            }
            if (iArray == null || iArray[1] == 0) {
                bUiKeyPressLock = false;
            }
        }
        MainCanvas.clearInput();
    }

    public void drawTongList(Graphics g) {
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, imgArray[2], imgArray[7], imgArray[8], imgArray[9], imgArray[4], sArray[0]);
        //#else
//#        h = imgArray[4].getHeight();
//#        Tools.drawFrame(g, imgArray[2], imgArray[1], sArray[4], sArray[5], sArray[0]);
        //#endif
        //绘制顶层选项
        w = Constant.FONT_SMALL.stringWidth(sArray[0]);
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        //#if NOKIA_S60V5
         h = 41;
         startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#else
//#        h = 30;
//#        startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#endif
        Tools.drawShadowString(g, (byte) 1, sArray[0], startX, startY, selectColor, blackColor);
        //绘制选项两边箭头
        startX = startX - 5 - 3;//5为箭头宽度
        startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);//7为箭头高度
        Tools.drawArrow(g, imgArray[0], (byte) 1, startX, startY);//向左的箭头
        startX = startX + 5 + 3 + w + 3;
        Tools.drawArrow(g, imgArray[0], (byte) 2, startX, startY);//向右的箭头
        //绘制顶层选项蓝光
        startX = Constant.UI_START_X + 0;
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + 41 + h;
        //#else
//#        startY = Constant.UI_START_Y + 21 + h;
        //#endif
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, startY, w);
        //绘制半透明背景
        //#if NOKIA_S60V5
         h = Constant.END_LINE - 41 - h;
        //#else
//#        h = Constant.DRAW_HEIGHT - 21 - 25 - h;
        //#endif
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[3], 0, 0, w, imgArray[3].getHeight(), Constant.TRANS_NONE);
        //绘制翻页
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Tools.getPageStrWidth(sTotalPage, sCurrentPage) >> 1);
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - imgArray[6].getHeight() >> 1);
        //#else
//#        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25 + (25 - imgArray[6].getHeight() >> 1);
        //#endif
        Tools.drawPage(g, sTotalPage, sCurrentPage, imgArray[6], imgArray[0], startX, startY);
        //绘制帮派列表
        w = Constant.FONT_SMALL.stringWidth(sArray[3]);
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        //#if NOKIA_S60V5
         h = h / num;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        if (tongNum > 0) {
            int temp = (sCurrentPage * num < tongNum) ? sCurrentPage * num : tongNum;
            for (int i = (sCurrentPage - 1) * num; i < temp; i++) {
                //#if NOKIA_S60V5
                 startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
                         + (i - (sCurrentPage - 1) * num) * h;
                //#else
//#                startY = Constant.UI_START_Y + 65 + (i - (sCurrentPage - 1) * num) * h;
                //#endif
                Tools.drawShadowString(g, (byte) 1, sArray[1] + tongLv[i] + sArray[2] + tongName[i], startX,
                        startY, whiteColor, blackColor);
            }
        }
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        //#if NOKIA_S60V5
         h = (Constant.END_LINE - (41 << 1)) / num;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        if (bySelectIndex == 1) {
            Tools.drawSelectMask(g, (byte) 2, imgArray[1], startX, iPositionY, w);
        } //        else if (bySelectIndex == selectNum) {
        //            Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, iPositionY, w);
        //        }
        else {
            Tools.drawGapSlectMask(g, imgArray[1], null, false, h, startX, iPositionY, w);
        }
        if (byState == 1) {
            //绘制遮罩
            startX = Constant.UI_START_X + 0;
            startY = Constant.UI_START_Y + 0;
            w = Constant.DRAW_WIDTH;
            //#if NOKIA_S60V5
             h = Constant.END_LINE;
            //#else
//#            h = Constant.DRAW_HEIGHT;
            //#endif
            Tools.drawTilePic(g, (byte) 2, iUiX, iUiY, h, imgArray[3], 0, 0, w,
                    imgArray[3].getHeight(), Constant.TRANS_NONE);
            //弹出菜单
            Tools.drawPopOperation(g, imgArray[5], 0x989898, 0x7c7c7c, menu, menuWidth, menuH,
                    menuSpaceH, whiteColor, selectColor, menuSelectIndex, 0, 0);
            //绘制选择条
            startX = Constant.UI_START_X + 0;
            w = Constant.DRAW_WIDTH;
            //#if NOKIA_S60V5
             Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, menuPositionY, w, imgArray[0], imgArray[4], 1, 2, 47, 21,
                     imgArray[4], 100, 3, 45, 20);
            //#else
//#            Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, menuPositionY, w, imgArray[0], imgArray[4], 0, 0, 24, 12,
//#                    imgArray[4], 49, 0, 23, 12);
            //#endif
        }
    }

    public void clearTongList() {
        sArray = null;
        tongId = null;
        tongName = null;
        imgArray = null;
        menu = null;
        tongLv = null;
        tongMerNum = null;
        tongDate = null;
    }

    /*********************帮派技能学习**************************************/
    public void initTongSkill() {
        imgArray = new Image[5];
        try {
            //箭头图片
            this.imgArray[0] = ResManager.createImage(90000041);
            //蓝色光片
            this.imgArray[1] = Tools.createPicFromGrayscale(ResManager.createImage(90000029), 0x0099ff);
            //数字
            this.imgArray[2] = ResManager.createImage(90000062);
            this.imgArray[2] = Tools.makeTransparent(this.imgArray[2], 220);
            //边角
            this.imgArray[3] = ResManager.createImage(90000050);
            this.imgArray[3] = Tools.makeTransparent(this.imgArray[3], -1);
            //文字图片
            this.imgArray[4] = ResManager.createImage(90000043);
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    public String[] tongSkillstr = {"阿姨说，生气的时候不要吵架，可以不说话，不洗他衣服，但是不要和他吵架。"};
    public static int tongSkill_index;

    public void drawTongSkill(Graphics g) {
        int rect_x = 2, rect_y = 85;
        int rect_w = Constant.SCREEN_WIDTH - 4;
        int rect_h = Constant.FONT_SMALL_HEIGHT * 3;
        int rect_spacing = 5;//框之间的间距
        for (int i = 0; i < 3; i++) {
            Tools.drawNewFillRect(g, imgArray[3], 8, 8, 7, 7, rect_x, rect_y + (14 + rect_h + rect_spacing) * i, rect_h + 14, 0x989898);
            Tools.drawShadowString(g, (byte) 1, "还魂咒", 9, rect_y + 7 + (14 + rect_h + rect_spacing) * i, 0x00E7FF, 0x000000);
            //
            g.setColor(0x807f7f);
            g.fillRoundRect(9, rect_y + 7 + Constant.FONT_SMALL_HEIGHT * 2
                    + (14 + rect_h + rect_spacing) * i - 2,
                    Constant.FONT_SMALL.stringWidth("还魂咒"), Constant.FONT_SMALL_HEIGHT + 4,
                    Constant.FONT_SMALL_HEIGHT + 4, Constant.FONT_SMALL_HEIGHT + 4);
            Tools.drawShadowString(g, (byte) 1, "学习", 9 + (Constant.FONT_SMALL.stringWidth("还魂咒")
                    - Constant.FONT_SMALL.stringWidth("返回")) / 2, rect_y + 7 + Constant.FONT_SMALL_HEIGHT * 2
                    + (14 + rect_h + rect_spacing) * i, 0xfff000, 0x000000);
            Tools.drawParagraph(g,
                    9 + Constant.FONT_SMALL.stringWidth("还魂咒") + 4,
                    rect_y + 7 + (14 + rect_h + rect_spacing) * i, Constant.SCREEN_WIDTH - 22 - Constant.FONT_SMALL.stringWidth("还魂咒"), tongSkillstr[0], 0xFFFFFF, 0x000000, Constant.FONT_SMALL_HEIGHT);
        }
        //绘制选择
        Tools.drawTilePic(g, (byte) 1, 0,
                rect_y + 14 + rect_h - this.imgArray[1].getHeight() + (14 + rect_h + rect_spacing) * tongSkill_index,
                Constant.SCREEN_WIDTH, this.imgArray[1],
                0, 0,
                this.imgArray[1].getWidth(), this.imgArray[1].getHeight(), Constant.TRANS_NONE);
        g.setColor(0x000000);
        g.drawLine(0, rect_y + 14 + rect_h + (14 + rect_h + rect_spacing) * tongSkill_index,
                Constant.SCREEN_WIDTH, rect_y + 14 + rect_h + (14 + rect_h + rect_spacing) * tongSkill_index);
    }

    public void updateTongSkill() {
        if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
            tongSkill_index = tongSkill_index < 2 ? (tongSkill_index + 1) : 0;
        }
        if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
            tongSkill_index = tongSkill_index > 0 ? (tongSkill_index - 1) : 2;
        }
        if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回
            //跳转到漫游界面
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        }
    }
    //******************宠物合成开始*************************//
    /******************************************帮派大厅*******************************/
    private int byMaxSelectIndex;
    private int bySelectIndex2;

    public void initTongBuilding() {
        bUiKeyPressLock = false;
        this.iWidth = 232;
        this.byPopUpState = 1;
        this.iHeight = 138;
        GameBean.b_WAIT_NET_MSG_BACK = false;
        this.byMaxSelectIndex = 4;
        //对话
        this.iStartX = iUiX + ((Constant.SCREEN_WIDTH - this.iWidth) >> 1);
        this.iStartY = iUiY + ((Constant.SCREEN_HEIGHT - this.iHeight) >> 1) + 10;
        this.iPositionY = iStartY - 6;
        try {
            //弹出层的图片数组
            this.imgArray = new Image[4];
            this.imgArray[0] = Tools.makeTransparent(ResManager.createImage(90000051), -1);
            this.imgArray[1] = Tools.makeTransparent(10, this.iHeight + this.iHeight / 10, 220, 0x989898);
            this.imgArray[2] = ResManager.createImage(90000044);
            this.imgArray[3] = Tools.createPicFromGrayscale(ResManager.createImage(90000029), 0x0099ff);
            this.sArray = new String[]{"帮派介绍", "建筑升级", "帮派信息", "帮主让位", "领取工资", "请出帮派", "查看人员", "解散帮派", "退出帮派", "兄弟帮是会员的天堂，这所担负可以随意，兄弟帮无地帮"};
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void updateTongBuilding() {
        if (this.byPopUpState < 4) {
            this.byPopUpState++;
            return;
        }
        if (GameBean.b_WAIT_NET_MSG_BACK) {
            return;
        }
        if (!bUiKeyPressLock) {
            if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                if (this.bySelectIndex > 0) {
                    this.bySelectIndex--;
                    if (this.bySelectIndex == 0) {
                        this.iArray = new int[]{2, 1, iStartY - 6, 2, 55, 5};
                    } else {
                        this.iArray = new int[]{2, 1, this.iStartY + 55 - 6 + (this.bySelectIndex - 1) * 20, 2, 20, 3};
                    }
                    this.bUiKeyPressLock = true;
                }
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                if (this.bySelectIndex < this.byMaxSelectIndex) {
                    this.bySelectIndex++;
                    if (this.bySelectIndex == 0) {
                        this.iArray = new int[]{1, 1, iStartY - 6, 2, 55, 5};
                    } else {
                        this.iArray = new int[]{1, 1, this.iStartY + 55 - 6 + (this.bySelectIndex - 1) * 20, 2, 20, 3};
                    }
                    this.bUiKeyPressLock = true;
                }
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)) {
                if (this.bySelectIndex2 == 1) {
                    this.bySelectIndex2 = 0;
                }
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
                if (this.bySelectIndex2 == 0) {
                    this.bySelectIndex2 = 1;
                }
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                switch ((this.bySelectIndex - 1) * 2 + this.bySelectIndex2) {
                    case 0://建筑升级
                        break;
                    case 1://帮派信息
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DESCRIPT, Constant.SOCKET_MSG_TYPE_LOGIC);
                        break;
                    case 2://帮助让位
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_MEMBER_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                        break;
                    case 3://领取工资
                        break;
                    case 4://请出帮派
                        break;
                    case 5://查看人员
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_MEMBER_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                        break;
                    case 6://解散帮派
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DISMISS, Constant.SOCKET_MSG_TYPE_LOGIC);
                        GameBean.BY_CMD_TONG_DIMISS = 1;
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DISMISS, Constant.SOCKET_MSG_TYPE_LOGIC);
                        MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                        break;
                    case 7://退出帮派
                        break;
                }
            }
        } else {
            this.iPositionY = Tools.updateLinePos(iArray, this.iPositionY);
            if (this.iArray == null || this.iArray[1] == 0) {
                this.bUiKeyPressLock = false;
            }
        }
        MainCanvas.clearInput();
    }

    public void drawTongBuilding(Graphics g) {
        //#if NOKIA_S60V5
         Tools.drawPopUp(g, this.byPopUpState, this.iStartX, iStartY, this.iWidth, this.iHeight, this.imgArray[0], this.imgArray[1], (byte) 1, this.imgArray[2], 22, 0, 21, 10, this.imgArray[2], 0, 0, 22, 10, this.sArray[0], null);
        //#else
//#        Tools.drawPopUp(g, this.byPopUpState, this.iStartX, iStartY, this.iWidth, this.iHeight, this.imgArray[0], this.imgArray[1], (byte) 1, this.imgArray[2], 0, 0, 22, 10, this.imgArray[2], 22, 0, 21, 10, this.sArray[0], null);
        //#endif
        if (this.byPopUpState < 4) {
            return;
        }
        int startY = iStartY + 55;
        //绘制菜单
        for (int i = 0; i < 4; i++) {
            g.setColor(0x8d8d8d);
            g.drawRegion(this.imgArray[0], 27, 0, 5, 14, Constant.TRANS_NONE, iStartX + 3, startY + 3, 0); //头
            g.drawRegion(this.imgArray[0], 27, 0, 5, 14, Constant.TRANS_ROT180, iStartX + this.iWidth - 3 - 5, startY + 3, 0); //尾
            g.fillRect(iStartX + 3 + 5, startY + 3, iWidth - 16, 14);
            Tools.drawShadowString(g, (byte) 1, this.sArray[2 * i + 1], iStartX + 8, startY + 1, ((i == (this.bySelectIndex - 1)) && (this.bySelectIndex2 == 0)) ? 0x09c5ea : 0xfffeff, 0x5f5f5f);
            Tools.drawShadowString(g, (byte) 1, this.sArray[2 * i + 2], iStartX + iWidth - 8 - Constant.FONT_CHAR_WIDTH * 4, startY + 1, ((i == (this.bySelectIndex - 1)) && (this.bySelectIndex2 == 1)) ? 0x09c5ea : 0xfffeff, 0x5f5f5f);
            startY += 20;
        }
        startY = iStartY + 18;
        //绘制帮派描述
        Tools.drawParagraph(g, iStartX + 8, startY, this.iWidth - 22, this.sArray[9], 0x353638, Constant.FONT_CHAR_WIDTH, -1);
        //绘制选中线
        g.setColor(0x000000);
        g.drawLine(this.iStartX, this.iPositionY + 23, this.iUiX + Constant.SCREEN_WIDTH, this.iPositionY + 23);
        //选中状态
        Tools.drawTilePic(g, (byte) 1, this.iUiX, this.iPositionY, Constant.SCREEN_WIDTH, this.imgArray[3], 0, 0, this.imgArray[3].getWidth(), this.imgArray[3].getHeight(), Constant.TRANS_NONE);
    }

    public void clearTongBuilding() {
        this.imgArray = null;
    }
    /********************************帮派成员列表************************/
    short tongMemberNum;

    public void initTongMemberList() {
        bUiKeyPressLock = false;
        index = -1;
        tempIndex = -1;
        byPopUpState = 0;
        byState = 0;
        //#if NOKIA_S60V5
         imgArray = new Image[16];
         imgArray[0] = ResManager.createImage(90000041);//箭头
         imgArray[1] = Tools.makeBlueMask();//蓝光
         imgArray[2] = ResManager.createImage(90000017);//背景
         imgArray[3] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x232323);//半透明背景
         imgArray[4] = ResManager.createImage(90000043);//文字
         //弹出层图片
         imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);
         imgArray[6] = Tools.makeTransparent(10, 55 + 55 / 10, 220, 0x989898);
         imgArray[7] = ResManager.createImage(90000044);
         imgArray[8] = Tools.makeTransparent(ResManager.createImage(90000050), 255);//菜单背景图片
         imgArray[9] = Tools.makeTransparent(ResManager.createImage(90000052), 200); //弹出层图片
         imgArray[10] = Tools.makeTransparent(10, 88, 200, 0xccb5a1);//背景颜色层
         imgArray[11] = ResManager.createImage(90000044); //确定
         imgArray[12] = ResManager.createImage(90000047);//数字图片
         imgArray[13] = ResManager.createImage(90000084);//方向键
         imgArray[14] = ResManager.createImage(90000085);//确定键
         imgArray[15] = ResManager.createImage(90000086);//底部蓝条
        //#else
//#        imgArray = new Image[13];
//#        try {
//#            //箭头图片
//#            imgArray[0] = ResManager.createImage(90000041);
//#            //蓝色光片
//#            imgArray[1] = Tools.makeBlueMask();
//#            //背景图片
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[2] = ResManager.createImage(90000017);
//# //            imgArray[2] = Tools.ZoomImage(imgArray[2], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            this.imgArray[2] = ResManager.createImage(90000017);
            //#endif
//#            //半透背景图片
//#            imgArray[3] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x232323);
//#            //确定、返回图片
//#            imgArray[4] = ResManager.createImage(90000043);
//#            //弹出层图片
//#            imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);
//#            imgArray[6] = Tools.makeTransparent(10, 55 + 55 / 10, 220, 0x989898);
//#            imgArray[7] = ResManager.createImage(90000044);
//#            imgArray[8] = Tools.makeTransparent(ResManager.createImage(90000050), 255);//菜单背景图片
//#            imgArray[9] = Tools.makeTransparent(ResManager.createImage(90000052), 200); //弹出层图片
//#            imgArray[10] = Tools.makeTransparent(10, 88, 200, 0xccb5a1);//背景颜色层
//#            imgArray[11] = ResManager.createImage(90000044); //确定
//#            imgArray[12] = ResManager.createImage(90000047);//数字图片
//#        } catch (Exception e) {
//#            if (Constant.DEBUG) {
//#                e.printStackTrace();
//#            }
//#        }
        //#endif

        //测试
        initTongMemberNum((short) 25);
        for (int i = 0; i < 25; i++) {
            initTongMemberList(i, i, "帮派成员测试" + i, (byte) 1, i, (byte) 1);
        }
    }

    public void initTongMemberNum(short Num) {
        tongMemberNum = Num;
        tongId = new long[tongMemberNum];
        tongName = new String[tongMemberNum];
        duty = new byte[tongMemberNum];
        level = new int[tongMemberNum];
        onLine = new byte[tongMemberNum];

        sArray = new String[]{"我的帮派", "成员列表", "/", "页", "在线", "不在线", // 0 - 5
            "【", "】", " - ", "查看", "帮派列表", "退出帮派", "您确定要退出帮派么", // 6 - 12
            "您还未加入任何帮派", "【副帮主】25 - 测试成员长度", "确定", "返回"// 13 - 16
        };
        //#if NOKIA_E72
//#         num = 5;
        //#else
        num = 10;
        //#endif
        sCurrentPage = 1;
        sTotalPage = (short) ((tongMemberNum % num > 0 || tongMemberNum == 0) ? (tongMemberNum / num + 1) : (tongMemberNum / num));
//        selectNum = (byte) ((sCurrentPage * num < tongMemberNum) ? num + 2 : tongMemberNum - (sCurrentPage - 1) * num + 2);
        selectNum = (byte) ((sCurrentPage * num < tongMemberNum) ? num + 1 : tongMemberNum - (sCurrentPage - 1) * num + 1);
        bySelectIndex = 1;
        //#if NOKIA_S60V5
         iPositionY = Constant.UI_START_Y + 41;
        //#else
//#        iPositionY = Constant.UI_START_Y + 21;
        //#endif
    }

    public void initTongMemberList(int index, long id, String name, byte duty, int level, byte onLine) {
        tongId[index] = id;
        tongName[index] = name;
        this.duty[index] = duty;
        this.level[index] = level;
        this.onLine[index] = onLine;
    }

    public int setIndex(long id) {
        for (int i = 0; i < tongId.length; i++) {
            if (id == tongId[i]) {
                return i;
            }
        }
        return 0;
    }

    public void setTongMember(int index) {
        tongId[index] = tongId[tongMemberNum - 1];
        tongName[index] = tongName[tongMemberNum - 1];
        duty[index] = duty[tongMemberNum - 1];
        level[index] = level[tongMemberNum - 1];
        onLine[index] = onLine[tongMemberNum - 1];

        long[] tempId = tongId;
        String[] tempName = tongName;
        byte[] tempDuty = duty;
        int[] templevel = level;
        byte[] tempOnLine = onLine;

        tongMemberNum--;
        tongId = new long[tongMemberNum];
        tongName = new String[tongMemberNum];
        duty = new byte[tongMemberNum];
        level = new int[tongMemberNum];
        onLine = new byte[tongMemberNum];
        for (int i = 0; i < tongMemberNum; i++) {
            tongId[i] = tempId[i];
            tongName[i] = tempName[i];
            duty[i] = tempDuty[i];
            level[i] = templevel[i];
            onLine[i] = tempOnLine[i];
        }

        sCurrentPage = 1;
        sTotalPage = (short) ((tongMemberNum % num > 0 || tongMemberNum == 0) ? (tongMemberNum / num + 1) : (tongMemberNum / num));
        selectNum = (byte) ((sCurrentPage * num < tongMemberNum) ? num + 2 : tongMemberNum - (sCurrentPage - 1) * num + 2);
        bySelectIndex = 1;
        iPositionY = Constant.UI_START_Y + 21;
    }

    public void updateTongMemberList() {
        if (!bUiKeyPressLock) {
            switch (byState) {
                case 0:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            if (selectNum > 1) {
                                //#if NOKIA_S60V5
                                 h = (Constant.END_LINE - (41 << 1)) / num;
                                 startY = Constant.UI_START_Y + (41 << 1) + h * (selectNum - 2);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                startY = Constant.UI_START_Y + 65 + h * (selectNum - 2);
                                //#endif
                                bySelectIndex = selectNum;
                            } else {
                                return;
                            }
                        } else if (bySelectIndex == 2) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / num;
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 3);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 3);
                            //#endif
                            bySelectIndex--;
                        }
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == selectNum) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / num;
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 1);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 1);
                            //#endif
                            bySelectIndex++;
                        }
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)) {
                        if (bySelectIndex > 1 && sCurrentPage > 1) {//向左翻页
                            bUiKeyPressLock = true;
                            sCurrentPage--;
                            selectNum = (byte) ((sCurrentPage * num < tongMemberNum) ? num + 1 : tongMemberNum - (sCurrentPage - 1) * num + 1);
                            //#if NOKIA_S60V5
                             iPositionY = Constant.UI_START_Y + 41;
                            //#else
//#                            iPositionY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else if (bySelectIndex == 1) {//我的帮派
                            GameBean.L_CMD_TONG_ID = MainLogic.getInstance().gamePlayer.lTongId;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DESCRIPT, Constant.SOCKET_MSG_TYPE_LOGIC);
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
                        if (bySelectIndex > 1 && sCurrentPage < sTotalPage) {//向右翻页
                            bUiKeyPressLock = true;
                            sCurrentPage++;
                            selectNum = (byte) ((sCurrentPage * num < tongMemberNum) ? num + 1 : tongMemberNum - (sCurrentPage - 1) * num + 1);
                            //#if NOKIA_S60V5
                             iPositionY = Constant.UI_START_Y + 41;
                            //#else
//#                            iPositionY = Constant.UI_START_Y + 21;
                            //#endif
                            bySelectIndex = 1;
                        } else if (bySelectIndex == 1) {//我的帮派
                            GameBean.L_CMD_TONG_ID = MainLogic.getInstance().gamePlayer.lTongId;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_DESCRIPT, Constant.SOCKET_MSG_TYPE_LOGIC);
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false)
                            || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)
                            || MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                        if (bySelectIndex > 1) {
                            bUiKeyPressLock = true;
                            tempIndex = (sCurrentPage - 1) * num + bySelectIndex - 2;
                            if (MainLogic.getInstance().gamePlayer.lPlayerID == tongId[tempIndex]) {
                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "不可对自己进行操作！", (byte) 1, (byte) -1);
                            } else {
                                switch (duty[index]) {
                                    case 4:
                                        menu = new String[]{"加为好友", "发送消息", "移除帮派", "设定职位", "帮主让位"};
                                        break;
                                    case 3:
                                        menu = new String[]{"加为好友", "发送消息", "移除帮派", "设定职位"};
                                        break;
                                    case 2:
                                    case 1:
                                        menu = new String[]{"加为好友", "发送消息", "移除帮派"};
                                        break;
                                    case 0:
                                        menu = new String[]{"加为好友", "发送消息"};
                                        break;
                                }
                                //#if NOKIA_S60V5
                                 menuH = (Constant.END_LINE - (41 << 1)) / num;
                                 menuSpaceH = 20;
                                //#else
//#                                menuH = Constant.FONT_SMALL_HEIGHT + 2;
//#                                menuSpaceH = 10;
                                //#endif
                                menuWidth = Constant.DRAW_WIDTH >> 1;
                                menuHeight = menu.length * (menuH + menuSpaceH) - menuSpaceH;
                                menuSelectIndex = (byte) (menu.length % 2 == 0 ? (menu.length >> 1) : (menu.length >> 1) + 1);
                                //#if NOKIA_S60V5
                                 menuPositionY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                         + menuSelectIndex * (menuH + menuSpaceH);
                                //#else
//#                                menuPositionY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                        + menuSelectIndex * (menuH + menuSpaceH);
                                //#endif
                                byState = 1;
                            }
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级页面
                        Tools.openRoamMenu(false, (byte) 1, (byte) 8, 4);
                    }
                    break;
                case 1:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        tempIndex = (sCurrentPage - 1) * num + bySelectIndex - 2;
                        GameBean.L_PLAYER_ID = tongId[tempIndex];
                        switch (menuSelectIndex) {
                            case 1://加为好友
                                if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "战场中不允许添加好友!", (byte) 1, (byte) -1);
                                    byState = 0;
                                } else {
                                    GameBean.BY_CMD_FRIEND_NAME = tongName[tempIndex];
                                    GameBean.BY_CMD_FRIEND_TYPE = 1;
                                    GameBean.BY_CMD_FRIEND_MODE = 1;
                                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                    GameBean.b_WAIT_NET_MSG_BACK = true;
                                    byState = 0;
                                }
                                break;
                            case 2://发送消息
                                if (onLine[tempIndex] == 1) {
                                    GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_TONG_MEMBER_LIST;
                                    GameBean.BY_CMD_FRIEND_TYPE = 4;
                                    UiEquipment.chatOtherplayerId = tongId[tempIndex];//发送对象Id
                                    MainLogic.getInstance().uiEquipment.chatOtherplayerName = tongName[tempIndex];
                                    if (MainLogic.getInstance().uiEquipment.chatOtherplayerName.equals(MainLogic.getInstance().gamePlayer.sPlayerName)) {
                                        MainLogic.getInstance().uiEquipment.chatOtherplayerName = "";
                                    }
                                    MainLogic.getInstance().uiEquipment.chatshoutType = 3;
                                    MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                                    MainLogic.getInstance().inputInterFace.setInputInterFace(Constant.GAME_UI_CHAT, "私聊发送聊天");
                                    MainLogic.getInstance().inputInterFace.commonInput.setString(null);
                                    MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                                } else {
                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "玩家已下线!", (byte) 1, (byte) -1);
                                    byState = 0;
                                }
                                break;
                            case 3://移除帮派
                                if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "战场中不允许此操作!", (byte) 1, (byte) -1);
                                    byState = 0;
                                } else {
                                    if (duty[tempIndex] == 0) {
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_LEAVE, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        byState = 0;
                                    } else {
                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "只能移除没有职位的成员", (byte) 1, (byte) -1);
                                    }
                                }
                                break;
                            case 4://设定职位
                                menu = new String[]{"副帮主", "护法", "长老", "帮众"};
                                //#if NOKIA_S60V5
                                 menuH = (Constant.END_LINE - (41 << 1)) / num;
                                 menuSpaceH = 20;
                                //#else
//#                                menuH = Constant.FONT_SMALL_HEIGHT + 2;
//#                                menuSpaceH = 10;
                                //#endif
                                menuWidth = Constant.DRAW_WIDTH >> 1;
                                menuHeight = menu.length * (menuH + menuSpaceH) - menuSpaceH;
                                menuSelectIndex = (byte) (menu.length % 2 == 0 ? (menu.length >> 1) : (menu.length >> 1) + 1);
                                //#if NOKIA_S60V5
                                 menuPositionY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                         + menuSelectIndex * (menuH + menuSpaceH);
                                //#else
//#                                menuPositionY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                        + menuSelectIndex * (menuH + menuSpaceH);
                                //#endif
                                byState = 3;
                                break;
                            case 5://帮主让位
                                if (MainLogic.getInstance().gamePlayer.lPlayerID == GameBean.L_PLAYER_ID) {
                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请将帮主让给自己以外的其他成员", (byte) 1, (byte) -1);
                                } else {
                                    GameBean.B_CMD_TONG_DUTY = 4;
                                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_CHANGE_POSITION, Constant.SOCKET_MSG_TYPE_LOGIC);
                                    GameBean.B_CMD_TONG_DUTY = -1;
                                    byState = 0;
                                }
                                break;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级页面
                        bUiKeyPressLock = true;
                        byState = 0;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == 1 ? menu.length : (menuSelectIndex - 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == menu.length ? 1 : (menuSelectIndex + 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    }
                    break;
                case 2:
                    if (byPopUpState < 4) {
                        byPopUpState++;
                        MainCanvas.clearInput();
                        return;
                    }
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {//确认退出帮派
                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "战场中不允许退帮!", (byte) 1, (byte) -1);
                            byState = 0;
                        } else {
                            bUiKeyPressLock = true;
                            GameBean.L_PLAYER_ID = tongId[index];
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_LEAVE, Constant.SOCKET_MSG_TYPE_LOGIC);
                            byState = 0;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//取消退出帮派
                        bUiKeyPressLock = true;
                        byState = 0;
                    }
                    break;
                case 3:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == 1 ? menu.length : (menuSelectIndex - 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == menu.length ? 1 : (menuSelectIndex + 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级页面
                        bUiKeyPressLock = true;
                        byState = 0;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        switch (menuSelectIndex) {
                            case 1://设为“副帮主”
                                GameBean.B_CMD_TONG_DUTY = 3;
                                break;
                            case 2://设为“护法”
                                GameBean.B_CMD_TONG_DUTY = 2;
                                break;
                            case 3://设为“长老”
                                GameBean.B_CMD_TONG_DUTY = 1;
                                break;
                            case 4://设为“帮众”
                                GameBean.B_CMD_TONG_DUTY = 0;
                                break;
                        }
                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_CHANGE_POSITION, Constant.SOCKET_MSG_TYPE_LOGIC);
                        GameBean.B_CMD_TONG_DUTY = -1;
                        byState = 0;
                    }
                    break;
            }
        } else {
            switch (byState) {
                case 0:
                    iPositionY = Tools.updateLinePos(iArray, iPositionY);
                    break;
                case 1:
                case 3:
                    menuPositionY = Tools.updateLinePos(iArray, menuPositionY);
                    break;
            }
            if (iArray == null || iArray[1] == 0) {
                bUiKeyPressLock = false;
            }
        }
    }

    public void drawTongMemberList(Graphics g) {
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, imgArray[2], imgArray[13], imgArray[14], imgArray[15], imgArray[4], sArray[1]);
        //#else
//#        Tools.drawFrame(g, imgArray[2], imgArray[1], sArray[15], sArray[16], sArray[1]);
        //#endif
        //绘制选项
        w = Constant.DRAW_WIDTH >> 1;
        startX = Constant.UI_START_X + (w - Constant.FONT_SMALL.stringWidth(sArray[0]) >> 1);
        //#if NOKIA_S60V5
         h = 41;
         startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#else
//#        h = 30;
//#        startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#endif
        Tools.drawShadowString(g, (byte) 1, sArray[0], startX, startY, whiteColor, blackColor);
        startX = Constant.UI_START_X + w + (w - Constant.FONT_SMALL.stringWidth(sArray[1]) >> 1);
        Tools.drawShadowString(g, (byte) 1, sArray[1], startX, startY, selectColor, blackColor);
        //绘制选项箭头
        startX = Constant.UI_START_X + w + (w - Constant.FONT_SMALL.stringWidth(sArray[1]) >> 1) - 3 - 5;
        startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);
        Tools.drawArrow(g, imgArray[0], (byte) 1, startX, startY);
        startX = Constant.UI_START_X + w + (w - Constant.FONT_SMALL.stringWidth(sArray[1]) >> 1)
                + Constant.FONT_SMALL.stringWidth(sArray[1]) + 3;
        Tools.drawArrow(g, imgArray[0], (byte) 2, startX, startY);
        //绘制固定选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + 41 + h;
        //#else
//#        startY = Constant.UI_START_Y + 21 + h;
        //#endif
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, startY, w);
        //绘制半透明背景
        //#if NOKIA_S60V5
         h = Constant.END_LINE - 41 - h;
        //#else
//#        h = Constant.DRAW_HEIGHT - 21 - 25 - h;
        //#endif
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[3], 0, 0, w, imgArray[3].getHeight(), Constant.TRANS_NONE);
        //绘制成员列表
        w = Constant.FONT_SMALL.stringWidth(sArray[14]);
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        //#if NOKIA_S60V5
         h = h / num;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        if (tongMemberNum > 0) {
            int temp = (sCurrentPage * num < tongMemberNum) ? sCurrentPage * num : tongMemberNum;
            String str_duty = null;
            for (int i = (sCurrentPage - 1) * num; i < temp; i++) {
                switch (duty[i]) {
                    case 0:
                        str_duty = "帮众";
                        break;
                    case 1:
                        str_duty = "长老";
                        break;
                    case 2:
                        str_duty = "护法";
                        break;
                    case 3:
                        str_duty = "副帮主";
                        break;
                    case 4:
                        str_duty = "帮主";
                        break;
                }
                //#if NOKIA_S60V5
                 startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
                         + (i - (sCurrentPage - 1) * num) * h;
                //#else
//#                startY = Constant.UI_START_Y + 65 + (i - (sCurrentPage - 1) * num) * h;
                //#endif
                Tools.drawShadowString(g, (byte) 1, sArray[6] + str_duty + sArray[7], startX, startY, selectColor, blackColor);
                Tools.drawShadowString(g, (byte) 1, level[i] + sArray[8] + tongName[i],
                        startX + Constant.FONT_SMALL.stringWidth(sArray[6] + str_duty + sArray[7]), startY,
                        onLine[i] == 1 ? whiteColor : 0x999999, blackColor);
            }
        } else {
            startX = Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sArray[13]) >> 1;
            //#if NOKIA_S60V5
             startY = Constant.END_LINE >> 1;
            //#else
//#            startY = Constant.DRAW_HEIGHT >> 1;
            //#endif
            Tools.drawShadowString(g, (byte) 1, sArray[13], startX, startY, whiteColor, blackColor);
        }
        //绘制页码
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Tools.getPageStrWidth(sTotalPage, sCurrentPage) >> 1);
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - imgArray[12].getHeight() >> 1);
        //#else
//#        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25 + (25 - imgArray[12].getHeight() >> 1);
        //#endif
        Tools.drawPage(g, sTotalPage, sCurrentPage, imgArray[12], imgArray[0], startX, startY);
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        //#if NOKIA_S60V5
         h = (Constant.END_LINE - (41 << 1)) / num;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        if (bySelectIndex == 1) {
            Tools.drawSelectMask(g, (byte) 2, imgArray[1], startX, iPositionY, w);
        } else {
            Tools.drawGapSlectMask(g, imgArray[1], null, false, h, startX, iPositionY, w);
        }
        if (byState == 1 || byState == 3) {
            //#if NOKIA_S60V5
             Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.END_LINE, imgArray[3], 0, 0,
                     Constant.DRAW_WIDTH, imgArray[3].getHeight(), Constant.TRANS_NONE);
            //#else
//#            Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_HEIGHT, imgArray[3], 0, 0,
//#                    Constant.DRAW_WIDTH, imgArray[3].getHeight(), Constant.TRANS_NONE);
            //#endif
            Tools.drawPopOperation(g, imgArray[5], 0x989898, 0x7c7c7c, menu, menuWidth, menuH,
                    menuSpaceH, whiteColor, selectColor, menuSelectIndex, 0, 0);

            //#if NOKIA_S60V5
             Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, menuPositionY, w, imgArray[0],
                     imgArray[4], 100, 3, 45, 20, imgArray[4], 1, 2, 47, 21);
            //#else
//#            Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, menuPositionY, w, imgArray[0], imgArray[4], 0, 0, 24, 12,
//#                    imgArray[4], 49, 0, 23, 12);
            //#endif
        } else if (byState == 2) {
            startX = Constant.UI_START_X + 4;
            //#if NOKIA_S60V5
             Tools.drawPopUp(g, byPopUpState, startX, startY, Constant.SCREEN_WIDTH - 8, 80, this.imgArray[9], this.imgArray[10],
                     (byte) 1, imgArray[11], 64, 0, 21, 10, imgArray[11], 43, 0, 22, 10, this.sArray[11], this.sArray[12]);
             startY = Constant.UI_START_Y + (Constant.END_LINE - 80 >> 1);
            //#else
//#            Tools.drawPopUp(g, byPopUpState, startX, startY, Constant.SCREEN_WIDTH - 8, 80, this.imgArray[9], this.imgArray[10],
//#                    (byte) 1, imgArray[11], 43, 0, 22, 10, imgArray[11], 64, 0, 21, 10, this.sArray[11], this.sArray[12]);
//#            startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - 80 >> 1);
            //#endif

            if (byPopUpState < 4) {
                return;
            }
        }
    }

    public void clearTongMemberList() {
        sArray = null;
        duty = null;
        level = null;
        onLine = null;
        tongName = null;
        imgArray = null;
    }

    /********************************帮派信息************************/
    public void initTongInfo() {
        bUiKeyPressLock = false;
        byState = 0;
        bySelectIndex = 1;
        sArray = new String[]{"我的帮派", "帮派名称：", "帮会代号：", "帮    主：", "帮派等级：",//0 - 4
            "帮派人数：", "帮派资金：", "我的帮贡：", "帮派宣言：", "成员列表", // 5 - 9
            "退出帮派", "您确定要退出帮派么？", "帮派信息", "返回"//10 - 13
        };
        //#if NOKIA_S60V5
         imgArray = new Image[11];
         imgArray[0] = ResManager.createImage(90000041);//箭头
         imgArray[1] = Tools.makeBlueMask();//蓝光
         imgArray[2] = ResManager.createImage(90000017);//背景
         imgArray[3] = ResManager.createImage(90000043);//文字
         imgArray[4] = Tools.makeTransparent(ResManager.createImage(90000051), 255);//弹出层边框
         imgArray[5] = Tools.makeTransparent(10, 80 + 80 / 10, 200, 0xccb5a1);//弹出层背景
         imgArray[6] = ResManager.createImage(90000044);//弹出层选项
         imgArray[7] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x232323);//半透明背景
         imgArray[8] = ResManager.createImage(90000084);//方向键
         imgArray[9] = ResManager.createImage(90000085);//确定键
         imgArray[10] = ResManager.createImage(90000086);//底部蓝条
         iPositionY = Constant.UI_START_Y + 41;
        //#else
//#        imgArray = new Image[8];
//#        iPositionY = Constant.UI_START_Y + 21;
//#        try {
//#            //箭头图片
//#            imgArray[0] = ResManager.createImage(90000041);
//#            //蓝色光片
//#            imgArray[1] = Tools.makeBlueMask();
//#            //背景图片
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[2] = ResManager.createImage(90000017);
//# //            imgArray[2] = Tools.ZoomImage(imgArray[2], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            this.imgArray[2] = ResManager.createImage(90000017);
            //#endif
//#            //确定返回
//#            this.imgArray[3] = ResManager.createImage(90000043);
//#            //弹出层边框图片
//#            imgArray[4] = Tools.makeTransparent(ResManager.createImage(90000051), 255);
//#            //弹出层背景图片
//#            imgArray[5] = Tools.makeTransparent(10, 80 + 80 / 10, 200, 0xccb5a1);
//#            //弹出层选项按钮
//#            imgArray[6] = ResManager.createImage(90000044);
//#            //半透背景图片
//#            imgArray[7] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 220, 0x232323);
//#        } catch (Exception e) {
//#            if (Constant.DEBUG) {
//#                e.printStackTrace();
//#            }
//#        }
        //#endif
        sData = new String[8];
//        sData = new String[]{"洪兴帮", "洪", "蒋震", "N级", "110",//0 - 4
//            "N金币", "0", "客家帮派，1930年由中国宝安县蒋氏家族后人蒋震开山立派。"//5 - 8
//        };//测试数据
    }

    public void initTongInfo(String Name, String NO, String leaderName, byte lv, byte merNum, byte merMaxNum, long money, long myMoney, String ADS) {
        sData[0] = Name;
        sData[1] = NO;
        sData[2] = leaderName;
        sData[3] = lv + "级";
        sData[4] = merNum + "/" + merMaxNum;
        sData[5] = "" + money;
        sData[6] = "" + myMoney;
        sData[7] = ADS;
    }

    public void updateTongInfo() {
        if (!bUiKeyPressLock) {
            switch (byState) {
                case 0:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一级菜单
                        bUiKeyPressLock = true;
                        switch (GameBean.BY_PRE_GAME_UI_STATE) {
                            case Constant.GAME_UI_TONG_LIST:
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                break;
                            case Constant.GAME_UI_ROAM_MENU:
                                Tools.openRoamMenu(false, (byte) 1, (byte) 8, 4);
                                break;
                            case Constant.GAME_UI_NPC_TALK:
                                MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                                break;
                            default:
                                MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
                                break;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)
                            || MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
                        bUiKeyPressLock = true;
                        if (MainLogic.getInstance().gamePlayer.sTongName != null
                                && MainLogic.getInstance().gamePlayer.sTongName.substring(1, 2).equals(sData[1])) {
                            if (bySelectIndex == 1) {
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_MEMBER_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            }
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {//退出帮派
                        byState = 1;
                        byPopUpState = 0;
                    }
                    break;
                case 1:
                    if (byPopUpState < 4) {
                        byPopUpState++;
                        MainCanvas.clearInput();
                        return;
                    }
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {//确认退出帮派
                        bUiKeyPressLock = true;
                        if (MainLogic.getInstance().gamePlayer.sTongName == null) {
                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "您目前没有帮派", (byte) 1, (byte) -1);
                        } else if (MainLogic.getInstance().gamePlayer.bTongDuty == 4) {
                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请将帮主让给他人再退帮", (byte) 1, (byte) -1);
                        } else {
                            GameBean.L_PLAYER_ID = MainLogic.getInstance().gamePlayer.lPlayerID;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TONG_LEAVE, Constant.SOCKET_MSG_TYPE_LOGIC);
                        }
                        byState = 0;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//取消退出帮派
                        bUiKeyPressLock = true;
                        byState = 0;
                    }
                    break;
            }
        } else {
            iPositionY = Tools.updateLinePos(iArray, iPositionY);
            if (iArray == null || iArray[1] == 0) {
                bUiKeyPressLock = false;
            }
        }
    }

    public void drawTongInfo(Graphics g) {
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        if (MainLogic.getInstance().gamePlayer.sTongName != null
                && MainLogic.getInstance().gamePlayer.sTongName.substring(1, 2).equals(sData[1])) {
            //#if NOKIA_S60V5
             Tools.drawS60V5Frame(g, imgArray[2], imgArray[8], imgArray[9], imgArray[10], imgArray[3], 52, 2, 43, 22,
                     imgArray[3], 198, 26, 94, 25, sArray[0]);
             h = 41;
             startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
            //#else
//#//            Tools.drawFrame(g, startX, startY, imgArray[2], null, imgArray[1],
//#//                    imgArray[3], 0, 0, 24, 12, imgArray[3], 49, 0, 23, 12,
//#//                    sArray[0], whiteColor);
//#            Tools.drawFrame(g, imgArray[2], imgArray[1], sArray[10], sArray[13], sArray[0]);
//#            h = 30;
//#            startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
            //#endif
            w = Constant.DRAW_WIDTH >> 1;
            startX = Constant.UI_START_X + (w - Constant.FONT_SMALL.stringWidth(sArray[0]) >> 1);
            Tools.drawShadowString(g, (byte) 1, sArray[0], startX, startY, selectColor, blackColor);
            startX = Constant.UI_START_X + w + (w - Constant.FONT_SMALL.stringWidth(sArray[8]) >> 1);
            Tools.drawShadowString(g, (byte) 1, sArray[9], startX, startY, whiteColor, blackColor);
            //绘制选项箭头
            startX = Constant.UI_START_X + (w - Constant.FONT_SMALL.stringWidth(sArray[0]) >> 1) - 3 - 5;
            startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);
            Tools.drawArrow(g, imgArray[0], (byte) 1, startX, startY);
            startX = Constant.UI_START_X + (w - Constant.FONT_SMALL.stringWidth(sArray[0]) >> 1)
                    + Constant.FONT_SMALL.stringWidth(sArray[0]) + 3;
            Tools.drawArrow(g, imgArray[0], (byte) 2, startX, startY);
        } else {
            //#if NOKIA_S60V5
             Tools.drawS60V5Frame(g, imgArray[2], imgArray[8], imgArray[9], imgArray[10], imgArray[3], sArray[0]);
             h = 41;
             startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
            //#else
//#            Tools.drawFrame(g, startX, startY, imgArray[2], null, imgArray[1],
//#                    imgArray[3], 0, 0, 24, 12, imgArray[3], 49, 0, 23, 12,
//#                    sArray[12], whiteColor);
//#            h = 30;
//#            startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
            //#endif
            w = Constant.FONT_SMALL.stringWidth(sArray[12]);
            startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
            Tools.drawShadowString(g, (byte) 1, sArray[12], startX, startY, selectColor, blackColor);
            startX = startX - 3 - 5;
            startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);
            Tools.drawArrow(g, imgArray[0], (byte) 1, startX, startY);
            startX = startX + 3 + 5 + w + 3;
            Tools.drawArrow(g, imgArray[0], (byte) 2, startX, startY);
        }
        //绘制固定选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + (41 << 1);
         h = Constant.END_LINE - (41 << 1);
        //#else
//#        startY = Constant.UI_START_Y + 21 + 30;
//#        h = Constant.DRAW_HEIGHT - 21 - 25 - 30;
        //#endif
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, startY, w);
        //绘制半透明背景
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[7], 0, 0, w, imgArray[7].getHeight(), Constant.TRANS_NONE);
        //绘制“帮派名称”——“帮派资金”
        //#if NOKIA_S60V5
         startX = Constant.UI_START_X + 20;
         h = h / 12;
         startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1);
         w = Constant.DRAW_WIDTH - 40;
        //#else
//#        startX = Constant.UI_START_X + 15;
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
//#        startY = Constant.UI_START_Y + 60;
//#        w = Constant.DRAW_WIDTH - 30;
        //#endif
        for (int i = 0; i < 7; i++) {
            Tools.drawShadowString(g, (byte) 1, sArray[i + 1], startX, startY, selectColor, blackColor);
            Tools.drawShadowString(g, (byte) 1, sData[i], startX + Constant.FONT_SMALL.stringWidth(sArray[1]),
                    startY, whiteColor, blackColor);
            startY += h;
        }
        //#if NOKIA_E72
//#         Tools.drawShadowString(g, (byte) 1, sArray[8], Constant.SCREEN_WIDTH / 2 + 20, Constant.UI_START_Y + 60, selectColor, blackColor);
//#         //绘制帮会宣言内容
//#         Tools.drawParagraph(g, Constant.SCREEN_WIDTH / 2 + 20, Constant.UI_START_Y + 60 + h, Constant.SCREEN_WIDTH / 2 - 40, sData[sData.length - 1], whiteColor, h, blackColor);
        //#else
        //绘制“帮会宣言”
        Tools.drawShadowString(g, (byte) 1, sArray[8], startX, startY, selectColor, blackColor);
        //绘制帮会宣言内容
        startY += h;
        Tools.drawParagraph(g, startX, startY, w, sData[sData.length - 1], whiteColor, h, blackColor);
        //#endif
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, bySelectIndex == 1 ? (byte) 2 : (byte) 1, imgArray[1], startX, iPositionY, w);
        if (byState == 1) {
            w = Constant.DRAW_WIDTH - 20;
            h = 80;
            startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
            //#if NOKIA_S60V5
             Tools.drawBottom(g, imgArray[3], null, imgArray[10]);
             startY = Constant.UI_START_Y + (Constant.END_LINE - h >> 1);
             Tools.drawPopUp(g, byPopUpState, startX, startY, w, h, imgArray[4], 0x9C9C9C,
                     imgArray[6], 22, 0, 21, imgArray[6].getHeight(), imgArray[6], 0, 0, 22, imgArray[6].getHeight(),
                     sArray[10], sArray[11]);
            //#else
//#            startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - h >> 1);
//#            Tools.drawPopUp(g, byPopUpState, startX, startY, w, h, imgArray[4], 0x9C9C9C,
//#                    imgArray[6], 0, 0, 22, imgArray[6].getHeight(), imgArray[6], 22, 0, 21, imgArray[6].getHeight(),
//#                    sArray[10], sArray[11]);
            //#endif
        }
    }

    public void clearTongInfo() {
        sArray = null;
        imgArray = null;
        sData = null;
    }

    /********************************帮派建造************************/
    public void initTongMenu() {
        bUiKeyPressLock = false;
        sArray = new String[]{"帮派大堂", "帮派冶炼房", "帮派仓库", "帮派书院", "帮派杂货铺"};
        sData = new String[5];
        byPopUpState = 0;
        menuSelectIndex = 3;
        //#if NOKIA_S60V5
         h = 28;
         menuSpaceH = 10;
         iWidth = Constant.DRAW_WIDTH - 10 - (20 << 1);
         imgArray = new Image[9];
         imgArray[5] = ResManager.createImage(90000090);//方向键
         imgArray[6] = ResManager.createImage(90000086);//底部蓝条
         imgArray[7] = Tools.makeTransparent(Constant.DRAW_WIDTH, 10, 220, 0x252525);//半透明背景图片
         imgArray[8] = ResManager.createImage(90000043);//确定文字
        //#else
//#        h = 18;
//#        menuSpaceH = 3;
//#        iWidth = Constant.DRAW_WIDTH - 10 - (14 << 1);
//#        imgArray = new Image[5];
        //#endif
        menuH = Constant.FONT_SMALL_HEIGHT + menuSpaceH;
        menuWidth = 200;
        menuHeight = menuH * sArray.length + menuSpaceH + h;
        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1);
        menuPositionY = startY + h + menuSelectIndex * menuH;
        imgArray[0] = ResManager.createImage(90000051);
        imgArray[0] = Tools.makeTransparent(imgArray[0], 240);//透明度
        imgArray[1] = Tools.makeTransparent(10, menuHeight + menuHeight / 10, 240, 0x9C9C9C);
        imgArray[2] = ResManager.createImage(90000044);//图片文字
        imgArray[3] = Tools.makeTransparent(10, 56, 255, 0x9C9C9C);//背景颜色层
        imgArray[4] = Tools.makeBlueMask(); //蓝色光片
        rollindex = 0;
//        setTongMenuInfo(new byte[]{1, 5, 3, 4, 5}, new int[]{3000, 5000, 4000, 6000, 30000});
    }

    public void setTongMenuInfo(byte[] lv, int[] money) {
        //设置帮派大厅的提示信息
        if (lv[0] == 5) {
            sData[0] = "当前级别5级。";
        } else {
            sData[0] = "当前级别为" + lv[0] + "级，升级需要" + money[0] + "帮派资金，需要帮派等级" + (lv[0] + 1) + "级。升级后可增加帮派人数上限，是帮派其他建筑的升级条件。";
        }
        //设置帮派冶炼房的提示信息
        if (lv[1] == 5) {
            sData[1] = "当前级别5级，出售武器和护具，升级后可卖更高级别的物品，并且维修费和出售价格为75%。";
        } else {
            int temp = 0;
            switch (lv[1]) {
                case 1:
                    temp = 100;
                    break;
                case 2:
                    temp = 90;
                    break;
                case 3:
                    temp = 85;
                    break;
                case 4:
                    temp = 80;
                    break;
            }
            sData[1] = "当前级别" + lv[1] + "级，出售武器和护具，升级后可卖更高级别的物品，并且维修费和出售价格为" + temp + "%。升级需要" + money[1] + "帮派资金，需要帮派大堂" + (lv[1] + 1) + "级。";
        }
        //设置帮派仓库的提示信息
        if (lv[2] == 5) {
            sData[2] = "当前级别5级。帮派仓库只有帮主和副帮主可进行操作。";
        } else {
            sData[2] = "当前级别" + lv[2] + "级，帮派仓库只有帮主和副帮主可进行操作。升级需要" + money[2] + "帮派资金，需要帮派大堂" + (lv[2] + 1) + "级，升级后可增加仓库5格使用上限。";
        }
        //设置帮派书院的提示信息 
        if (lv[3] == 5) {
            sData[3] = "当前级别5级，学习帮派技能的唯一地点。级别越高，可学习的技能越多。";
        } else {
            sData[3] = "当前级别" + lv[3] + "级，学习帮派技能的唯一地点。级别越高，可学习的技能越多。升级需要" + money[3] + "帮派资金，需要帮派大堂" + (lv[3] + 1) + "级。";
        }
        //设置帮派杂货铺的提示信息
        if (lv[4] == 5) {
            sData[4] = "当前级别5级，出售价格为75%。";
        } else {
            int temp = 0;
            switch (lv[4]) {
                case 1:
                    temp = 100;
                    break;
                case 2:
                    temp = 90;
                    break;
                case 3:
                    temp = 85;
                    break;
                case 4:
                    temp = 80;
                    break;
            }
            sData[4] = "当前级别" + lv[4] + "级，出售价格为" + temp + "%。升级需要" + money[4] + "帮派资金，需要帮派大堂" + (lv[4] + 1) + "级。";
        }
        Tools.rollIndex = 0;
        iHeight = Tools.getParagraphHeight(sData[menuSelectIndex - 1], iWidth, menuH);
    }

    public void drawTongMenu(Graphics g) {
        //#if NOKIA_S60V5
         //绘制半透明背景
         Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_HEIGHT - 57,
                 imgArray[7], 0, 0, Constant.DRAW_WIDTH, imgArray[7].getHeight(), Constant.TRANS_NONE);
         Tools.drawBottom(g, imgArray[8], imgArray[5], imgArray[6]);
        //#endif
        //绘制菜单背景
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - menuWidth >> 1);
        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1);
        Tools.drawPopUp(g, byPopUpState, startX, startY, menuWidth, menuHeight, imgArray[0], imgArray[1], (byte) 1,
                imgArray[2], 22, 0, 21, 10, imgArray[2], 0, 0, 22, 10, null, null);
        if (byPopUpState < 4) {
            return;
        }
        //绘制菜单内容
        startY += h;
        for (int i = 0; i < sArray.length; i++) {
            Tools.drawShadowString(g, (byte) 1, sArray[i], startX + (menuWidth - Constant.FONT_SMALL.stringWidth(sArray[i]) >> 1),
                    startY + i * menuH + (menuH - Constant.FONT_SMALL_HEIGHT >> 1),
                    menuSelectIndex == i + 1 ? 0x00CCFF : 0xFFFFFF, 0x000000);
        }
        //#if NOKIA_S60V5
         //绘制提示信息背景
         startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - 57 - 80 - 39);
         startX = Constant.UI_START_X + 5;
         Tools.drawRoundRect(g, imgArray[0], imgArray[3], (byte) 1, Constant.DRAW_WIDTH - 10, 80, startX, startY);
         //绘制提示信息内容
         startX += 20;
         startY += 13;
         Tools.drawHCycleRollingParagraph(g, sData[menuSelectIndex - 1], iHeight, iWidth,
                 41, menuH, startX, startY, 0xFFFFFF, 0x000000);
        //#elif NOKIA_E72
//#         g.setColor(0x9c9c9c);
//#         g.fillRect(0, Constant.SCREEN_HEIGHT - Constant.FONT_SMALL_HEIGHT - 4, Constant.SCREEN_WIDTH, Constant.FONT_SMALL_HEIGHT + 4);
//#         Tools.drawShadowString(g, (byte) 1, sData[menuSelectIndex - 1], Constant.SCREEN_WIDTH - rollindex, Constant.SCREEN_HEIGHT - Constant.FONT_SMALL_HEIGHT - 2, 0xFFFFFF, 0x000000);
//#         rollindex += 3;
//#         if (Constant.SCREEN_WIDTH - rollindex + Constant.FONT_SMALL.stringWidth(sData[menuSelectIndex - 1]) + 10 < 0) {
//#             rollindex = 0;
//#         }
        //#else
//#
//#        //绘制提示信息背景
//#        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - 60 - 21);
//#        startX = Constant.UI_START_X + 5;
//#        Tools.drawRoundRect(g, imgArray[0], imgArray[3], (byte) 1, Constant.DRAW_WIDTH - 10, 60, startX, startY);
//#        //绘制提示信息内容
//#        startX += 14;
//#        startY += 7;
//#        Tools.drawHCycleRollingParagraph(g, sData[menuSelectIndex - 1], iHeight, iWidth,
//#                39, menuH, startX, startY, 0xFFFFFF, 0x000000);
        //#endif
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[4], startX, menuPositionY, w);
    }
    private static int rollindex;

    public void updateTongMenu() {
        if (byPopUpState < 4) {
            byPopUpState++;
            MainCanvas.clearInput();
            return;
        }
        if (!bUiKeyPressLock) {
            if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                bUiKeyPressLock = true;
                menuSelectIndex = (byte) (menuSelectIndex == 1 ? sArray.length : (menuSelectIndex - 1));
                startY = Constant.DRAW_HEIGHT - menuHeight >> 1;
                iArray = new int[]{2, 1, startY + h + menuSelectIndex * menuH, 2, 50, 5};
                Tools.rollIndex = 0;
                rollindex = 0;
                iHeight = Tools.getParagraphHeight(sData[menuSelectIndex - 1], iWidth, menuH);
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                bUiKeyPressLock = true;
                menuSelectIndex = (byte) (menuSelectIndex == sArray.length ? 1 : (menuSelectIndex + 1));
                startY = Constant.DRAW_HEIGHT - menuHeight >> 1;
                iArray = new int[]{1, 1, startY + h + menuSelectIndex * menuH, 2, 50, 5};
                Tools.rollIndex = 0;
                rollindex = 0;
                iHeight = Tools.getParagraphHeight(sData[menuSelectIndex - 1], iWidth, menuH);
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)
                    || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false)
                    || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                bUiKeyPressLock = true;
                GameBean.BY_CMD_TONG_BUILDING_TYPE = menuSelectIndex;
                MainLogic.getInstance().send(Constant.MSG_NET_TONG_NPC_UPGRADE, Constant.SOCKET_MSG_TYPE_LOGIC);
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//回到上一级菜单
                MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
            }
        } else {
            menuPositionY = Tools.updateLinePos(iArray, menuPositionY);
            if (iArray == null || iArray[1] == 0) {
                bUiKeyPressLock = false;
            }
        }
    }

    public void clearTongMenu() {
        sArray = null;
        imgArray = null;
        sData = null;
    }

    /*******************************帮派报名列表*****************************************/
    public void initApplyTongList() {
        bUiKeyPressLock = false;
        startX = 0;
        startY = 0;
        byState = 0;
        tempIndex = 0;
        tempVsIndex = 0;
        //#if NOKIA_E72
//#         num = 5;
        //#else
        num = 10;
        //#endif
        sArray = new String[]{"报名成功帮派", "成功报名帮派列表", "帮派：", "级", "VS", "没有对战帮派",//0 - 5
            " 确定", "返回" //6 - 7
        };
        //#if NOKIA_S60V5
         imgArray = new Image[10];
         imgArray[0] = ResManager.createImage(90000041);//箭头图片
         imgArray[1] = Tools.makeBlueMask();//蓝色光片
         imgArray[2] = ResManager.createImage(90000017);//背景
         imgArray[3] = Tools.makeTransparent(Constant.DRAW_WIDTH, 10, 220, 0x232323);//半透背景图片
         imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
         imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
         imgArray[6] = ResManager.createImage(90000047);//数字图片
         imgArray[7] = ResManager.createImage(90000084);//方向键
         imgArray[8] = ResManager.createImage(90000085);//确定键
         imgArray[9] = ResManager.createImage(90000086);//底部蓝条
        //#else
//#        imgArray = new Image[7];
//#        try {
//#            imgArray[0] = ResManager.createImage(90000041);//箭头图片
//#            imgArray[1] = Tools.makeBlueMask();//蓝色光片
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[2] = ResManager.createImage(90000017);
//# //            imgArray[2] = Tools.ZoomImage(imgArray[2], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            this.imgArray[2] = ResManager.createImage(90000017);
            //#endif
//#            imgArray[3] = Tools.makeTransparent(Constant.DRAW_WIDTH, 10, 220, 0x232323);//半透背景图片
//#            imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
//#            imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
//#            imgArray[6] = ResManager.createImage(90000047);//数字图片
//#        } catch (Exception e) {
//#            if (Constant.DEBUG) {
//#                e.printStackTrace();
//#            }
//#        }
        //#endif
        //测试用
//        GameBean.BY_CMD_APPLY_FIGHT_TYPE = 2;
//        getApplyTongNumber((short) 40);
//        for (int i = 0; i < 40; i++) {
//            getApplyTongListInfo(i, "测试测试测试", i);
//        }
    }

    public void getApplyTongNumber(short tongNum) {
        sCurrentPage = 1;
        if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 1) {
            tongName = new String[tongNum];
            level = new int[tongNum];
            sTotalPage = (short) ((tongNum % num > 0 || tongNum == 0) ? (tongNum / num + 1) : (tongNum / num));
        } else if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 2) {
            int tempNum = tongNum % 2 == 0 ? tongNum >> 1 : (tongNum >> 1) + 1;
            int tempVsNum = tongNum >> 1;
            tongName = new String[tempNum];
            level = new int[tempNum];
            tongNameVs = new String[tempVsNum];
            levelVs = new int[tempVsNum];
            sTotalPage = (short) ((tempNum % num > 0 || tempNum == 0) ? (tempNum / num + 1) : (tempNum / num));
        }
    }

    public void getApplyTongListInfo(int index, String name, int lev) {
        if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 1) {//冰封原战场
            tongName[index] = name;
            level[index] = lev;
        } else if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 2) {//落日谷战场
            if (index % 2 == 0) {//VS前面的帮派
                if (name.length() > 4) {
                    tongName[tempIndex] = name.substring(0, 3) + "…";
                } else {
                    tongName[tempIndex] = name;
                }
                level[tempIndex] = lev;
                tempIndex++;
            } else {//VS后面的帮派
                if (name.length() > 4) {
                    tongNameVs[tempVsIndex] = name.substring(0, 3) + "…";
                } else {
                    tongNameVs[tempVsIndex] = name;
                }
                levelVs[tempVsIndex] = lev;
                tempVsIndex++;
            }
        }
    }

    public void drawApplyTongList(Graphics g) {
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, imgArray[2], imgArray[7], imgArray[8], imgArray[9], imgArray[4], sArray[0]);
         h = 41;
         startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#else
//#        Tools.drawFrame(g, imgArray[2], imgArray[1], sArray[6], sArray[7], sArray[0]);
//#        h = 30;
//#        startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#endif
        //绘制顶层选项
        w = Constant.FONT_SMALL.stringWidth(sArray[1]);
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
        Tools.drawShadowString(g, (byte) 1, sArray[1], startX, startY, selectColor, blackColor);
        //绘制选项两边箭头
        startX = startX - 5 - 3;//5为箭头宽度
        startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);//7为箭头高度
        Tools.drawArrow(g, imgArray[0], (byte) 1, startX, startY);//向左的箭头
        startX = startX + 5 + 3 + w + 3;
        Tools.drawArrow(g, imgArray[0], (byte) 2, startX, startY);//向右的箭头
        //绘制顶层选项蓝光
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + 41 + h;
         h = Constant.END_LINE - 41 - h;
        //#else
//#        startY = Constant.UI_START_Y + 21 + h;
//#        h = Constant.DRAW_HEIGHT - 21 - 25 - h;
        //#endif
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, startY, w);
        //绘制半透明背景
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[3], 0, 0, w, imgArray[3].getHeight(), Constant.TRANS_NONE);
        //绘制翻页
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - imgArray[6].getHeight() >> 1);
        //#else
//#        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25 + (25 - imgArray[6].getHeight() >> 1);
        //#endif
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Tools.getPageStrWidth(sTotalPage, sCurrentPage) >> 1);
        Tools.drawPage(g, sTotalPage, sCurrentPage, imgArray[6], imgArray[0], startX, startY);
        //绘制帮派列表
        //#if NOKIA_S60V5
         h = h / num;
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        startX = Constant.UI_START_X + 15;
        if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 1) {//冰封原战场
            if (tongName.length > 0) {
                int temp = (sCurrentPage * num < tongName.length) ? sCurrentPage * num : tongName.length;
                for (int i = (sCurrentPage - 1) * num; i < temp; i++) {
                    //#if NOKIA_S60V5
                     startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
                             + (i - (sCurrentPage - 1) * num) * h;
                    //#else
//#                    startY = Constant.UI_START_Y + 65 + (i - (sCurrentPage - 1) * num) * h;
                    //#endif
                    Tools.drawShadowString(g, (byte) 1, sArray[2] + tongName[i], startX, startY, whiteColor, blackColor);
                    Tools.drawShadowString(g, (byte) 1, level[i] + sArray[3], Constant.UI_START_X + Constant.DRAW_WIDTH - 15, startY,
                            whiteColor, blackColor, Graphics.TOP | Graphics.RIGHT);
                }
            }
        } else if (GameBean.BY_CMD_APPLY_FIGHT_TYPE == 2) {//落日谷战场
            if (tongName.length > 0) {
                int temp = (sCurrentPage * num < tongName.length) ? sCurrentPage * num : tongName.length;
                for (int i = (sCurrentPage - 1) * num; i < temp; i++) {
                    startX = Constant.UI_START_X + 15;
                    //#if NOKIA_S60V5
                     startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
                             + (i - (sCurrentPage - 1) * num) * h;
                    //#else
//#                    startY = Constant.UI_START_Y + 65 + (i - (sCurrentPage - 1) * num) * h;
                    //#endif
                    Tools.drawShadowString(g, (byte) 1, level[i] + sArray[3], startX, startY, whiteColor, blackColor);
                    startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sArray[4]) >> 1) - 15;
                    Tools.drawShadowString(g, (byte) 1, tongName[i], startX, startY, whiteColor, blackColor, Graphics.TOP | Graphics.RIGHT);
                    if (tongName.length > tongNameVs.length && i == tongName.length - 1) {//有轮空的帮派
                        startX = Constant.UI_START_X + Constant.DRAW_WIDTH - 15;
                        Tools.drawShadowString(g, (byte) 1, sArray[5], startX, startY, whiteColor, blackColor, Graphics.TOP | Graphics.RIGHT);
                    } else {
                        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sArray[4]) >> 1);
                        Tools.drawShadowString(g, (byte) 1, sArray[4], startX, startY, whiteColor, blackColor);
                        startX = startX + Constant.FONT_SMALL.stringWidth(sArray[4]) + 15;
                        Tools.drawShadowString(g, (byte) 1, levelVs[i] + sArray[3], startX, startY, whiteColor, blackColor);
                        startX = Constant.UI_START_X + Constant.DRAW_WIDTH - 15;
                        Tools.drawShadowString(g, (byte) 1, tongNameVs[i], startX, startY, whiteColor, blackColor, Graphics.TOP | Graphics.RIGHT);
                    }
                }
            }
        }
        //绘制底层选项蓝光
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[1], startX, startY, w);
    }

    public void updateApplyTongList() {
        if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)) {
            if (sCurrentPage > 1) {
                sCurrentPage--;
            }
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
            if (sCurrentPage < sTotalPage) {
                sCurrentPage++;
            }
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)
                || MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {//返回上一界面
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        }
    }

    public void clearApplyTongList() {
        sArray = null;
        imgArray = null;
        tongName = null;
        level = null;
        tongNameVs = null;
        levelVs = null;
    }
}
